package com.miskatmobile.bb.linkedin;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class LinkedinHomeScreen extends MainScreen implements FieldChangeListener
{
	LinkedinAPI api;
	private ButtonField requestToken;
	private ButtonField accessToken;
	private BasicEditField pinCode;
	
    /**
     * Creates a new LinkedinHomeScreen object
     */
    public LinkedinHomeScreen()
    {        
    	super(USE_ALL_WIDTH | USE_ALL_HEIGHT);
        // Set the displayed title of the screen       
        setTitle("Linkedin");
        api = new LinkedinAPI();
        //api.requestToken();86774
        
        requestToken = new ButtonField("Request Token", ButtonField.CONSUME_CLICK);
        requestToken.setChangeListener(this);
        accessToken = new ButtonField("accessToken", ButtonField.CONSUME_CLICK);
        accessToken.setChangeListener(this);
        pinCode = new BasicEditField();
        add(pinCode);
        add(requestToken);//
        add(accessToken);
    }
    
    private LabelField createLabel(String text){
    	return new LabelField(text);
    }

	public void fieldChanged(Field field, int context) {
		if (field == requestToken)
			api.requestToken();//02042
			//add(createLabel(api.requestToken()));
		else if (field == accessToken){
			add(createLabel(api.accessToken(pinCode.getText().trim())));
			//api.accessToken(pinCode.getText().trim());
			add(createLabel(api.getPeople()));
			String body = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><share><comment>83% of employers will use social media to hire: 78% LinkedIn, 55% Facebook, 45% Twitter [SF Biz Times] http://bit.ly/cCpeOD</comment><content>"+
	 "<title>Survey: Social networks top hiring tool - San Francisco Business Times</title>"+
	 "<submitted-url>http://sanfrancisco.bizjournals.com/sanfrancisco/stories/2010/06/28/daily34.html</submitted-url>"+
	 "<submitted-image-url>http://images.bizjournals.com/travel/cityscapes/thumbs/sm_sanfrancisco.jpg</submitted-image-url>"+
  "</content>"+
  "<visibility>"+
	" <code>anyone</code>"+
  "</visibility>"+
"</share>";
			add(createLabel(api.shareActivities(body)));
			add(createLabel("END"));
			add(new ButtonField("End"));
		}
	}
}
